<?php
	$oReq = &App::getRequest();

    $iUploadedId = $oReq->get('imageid');

	if ( $iUploadedId )
	{
		
		if ( !empty($_FILES['image']['name']) )
		{
			$sDestPath = App::getParam('video.image.path');

 			App::loadClass('file/Image');
			$oImage = &new file_Image();

			if ($oImage->upload('image', $sDestPath, $iUploadedId, 'jpg'))
            {
            	$oImage->loadInfo($sDestPath.$iUploadedId.'.jpg');
				$oImage->_checkLimits();
			}

			//$this->addErrors($oImage->getErrors());

			if (!count($oImage->getErrors()))
	        {
				$oImage->makeThumbnail($sDestPath.$iUploadedId.'.jpg', App::getSetting('upload_set_size_thumb'), App::getSetting('upload_set_size_thumb'));
			}
			if (!count($oImage->getErrors()))
	        {
	        	$oImage->loadInfo($sDestPath.$iUploadedId.'.jpg');
	        	echo "<script>
window.parent.document.getElementById('vid_image_$iUploadedId').style.display='none';
var oImg = window.parent.document.getElementById('mainimage_$iUploadedId');
oImg.src = '". App::getParam('video.image.url').$iUploadedId.'.jpg?time='.time() ."';
oImg.width = ".$oImage->nW.";
oImg.height = ".$oImage->nH.";
</script>";
	        }else{
	        	echo "<script>alert(''";
	        	foreach($oImage->getErrors() as $sErr)
	        	{
	        		echo "+'$sErr'+'\n'";
	        	}
	        	echo ");</script>";
	        }
			//App::gotoUrl('public.account.submit.add-video', array('mode' => $oReq->get('mode'), 'uploaded' => $iUploadedId));
		}
		//$oTpl = &App::getTemplate();
    	//$oTpl->sTemplateFile = '_popup.html';
		//$oTpl->assign('iId', $iUploadedId);
		
		//return $this->oTpl->fetch('ChangeThumb.html');

		//echo "<script>window.parent.document.getElementById('mainimage_$iUploadedId').src = '". App::getParam('video.image.url').$iUploadedId.'.jpg?time='.time() ."';</script>";
	}
	exit(1);
?>